import { mixin_list } from '@tapui/mixins/mixin_list'
export const mixin_edit_list = {
  mixins: [mixin_list],
  data() {
    return {
      isQueryOnCreated: false,
      pageInfo: {
        currentPage: 1, // 当前页面
        pageSize: 5, // 每页记录数
        pageSizes: ['10', '50', '100'],
        totalCount: 0 // 总数
      },
      code: '',
      disableEditSubmit: false
    }
  },
  computed: {
    totalPage() {
      let total = parseInt(this.pageInfo.totalCount / this.pageInfo.pageSize) + (this.pageInfo.totalCount % this.pageInfo.pageSize > 0 ? 1 : 0)
      if (total <= 0) {
        total = 1
      }
      return total
    }
  },
  methods: {
    nextPage() {
      if (this.pageInfo.currentPage < this.totalPage) {
        this.doChangeIndex(this.pageInfo.currentPage + 1)
      }
    },
    prePage() {
      if (this.pageInfo.currentPage > 1) {
        this.doChangeIndex(this.pageInfo.currentPage - 1)
      }
    },
    /** 加载数据之后 */
    afterLoadData() {
      this.$emit('loaded', this.pageInfo.totalCount, this.code)
    },
    /** 刷新,页号不变*/
    doRefresh() {
      this.loadData({})
      this.$emit('updateData')
    },
    afterDoDelete(ids) {
      this.$emit('updateData')
    },
    changeView(disabled) {
      this.disableEditSubmit = disabled
      if (this.$refs.editForm) {
        this.$refs.editForm.disableEditSubmit = disabled
      }
      if (disabled) {
        this.rowDbClickActionType = 'view'
      } else {
        this.rowDbClickActionType = 'edit'
      }
    }
  }
}
